package hot_100;

import My_work.柠檬水找零;

public class 二叉树展开为链表 {
    public static void main(String[] args) {


    }

    TreeNode pro = null;

    public void flatten(TreeNode root) {
        Dfs(root);
        pro.left = pro.right = null;
    }

    public void Dfs(TreeNode root) {
        if (root == null)
            return;
        Dfs(root.right);
        Dfs(root.left);
        if (pro == null) {
            pro = root;
        } else {
            root.left = null;
            root.right = pro;
            pro = root;
        }
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
